﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Diagnostics.Contracts;
using SimpleIR;

namespace PInfoModel
{
	/// <summary>
	/// A class for representing program line information.
	/// </summary>
	public struct ProgLineIdentifier : IEquatable<ProgLineIdentifier>, IComparable<ProgLineIdentifier>
	{
		/// <summary>
		/// The use/mod line in the underlying intermediate representaion.
		/// </summary>
		public readonly int UseModLine;

		/// <summary>
		/// The line information in the source program.
		/// </summary>
		public readonly IRSourceLocation SourceLine;

		public ProgLineIdentifier(int uml, IRSourceLocation sl)
		{
			this.UseModLine = uml;
			this.SourceLine = sl;
		}

		public override string ToString()
		{
			return this.SourceLine.ToString() + "(" + this.UseModLine.ToString() + ")";
		}

		public static bool operator ==(ProgLineIdentifier pl1, ProgLineIdentifier pl2)
		{ return pl1.Equals(pl2); }

		public static bool operator !=(ProgLineIdentifier pl1, ProgLineIdentifier pl2)
		{ return !pl1.Equals(pl2); }

		public override int GetHashCode()
		{ return this.UseModLine; }

		public override bool Equals(object obj)
		{ return (obj is ProgLineIdentifier) && this.Equals((ProgLineIdentifier)obj); }

		public bool Equals(ProgLineIdentifier other)
		{ return this.UseModLine == other.UseModLine; }

		public int CompareTo(ProgLineIdentifier other)
		{ return this.SourceLine.CompareTo(other.SourceLine); }
	}
}
